#!/usr/bin/env python
# -*- coding: utf-8 -*-
# datetime: 2024/6/6 下午10:41
# Author: name
# File: bitsun_login.py
# ide: PyCharm
# description:
import requests


class BitSunLogin:
    def __init__(self, host, username, password):
        self.host = host
        self.session = requests.session()
        self.username = username
        self.password = password

    def user_login(self):
        # 使用环境信息
        # 使用用户名密码信息
        # 使用登录接口

        url = "/user/web/login"
        headers = {
            'Accept': 'application/json',
            'Content-Type': 'application/json;charset=UTF-8'
        }
        data = {
            "userName": self.username,
            "password": self.password,
            "verifyCode": "1234",
            "verifyId": "vf20220224000037",
            "identityType": 10, "regType": 10
        }
        response = self.session.post(url=self.host + url, headers=headers, json=data, verify=False)
        print(response.text)
        self.session.headers["sso-sessionid"] = str(response.json()["data"]["id"]) + "_1_1_1"
        self.session.headers["x-account-id"] = str(response.json()["data"]["id"])
        print("登录成功了-----------------", response.text)

        return self.session


if __name__ == '__main__':
    host = "http://bitsun-uat.cc0b9108c833e4298b9db565441546718.cn-shanghai.alicontainer.com/"
    username = "admin"
    password = "123456"
    BitSunLogin(host, username, password).user_login()
